<?php


if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
loadcache('plugin');
if(!defined('Adz_class')){include('Adz.class.php');}
include('acan_open.fun.php');
$referer = dreferer();

if($_GET['op']=='login'){
	if($weixin_id){
		$wxinfo = Adz::fetch_con('plugin_weixin',array('weixin_id'=>$weixin_id));
		if($wxinfo){
			if($_G['uid'] && $_G['uid'] != $wxinfo['uid']) {
				showmessage(lang('plugin/acan_open', 'chnweixinuserbeforebind'));
			} else {
				connect_login($wxinfo['uid']);
				manageaftlogin($wxinfo['uid']);
				loadcache('usergroups');
				$usergroups = $_G['cache']['usergroups'][$_G['groupid']]['grouptitle'];
				$param = array('username' => $_G['member']['username'], 'usergroup' => $_G['group']['grouptitle']);
				showmessage('login_succeed', './', $param, array('extrajs' => $ucsynlogin, 'showdialog' => 1, 'locationtime' => true));
			}
		}
	}
	if($_G['uid']){//bind loginned forum user?
		$examuid = Adz::fetch_con('plugin_weixin',array('uid'=>$_G['uid']));
		if(empty($examuid))	{	//loginned forum user not binded
			$weixin_info['uid'] = $_G['uid'];
			$rtn = addbindinfo($weixin_info); //bind info insert database
			if($rtn) {
				showmessage(lang('plugin/acan_open', 'bindsuccess').lang('plugin/acan_open', 'weixinuser').$info->username, '', array(), array('timeout' => '1', 'alert' => 'right'));
			} else {
				showmessage(lang('plugin/acan_open', 'bindfailure').lang('plugin/acan_open', 'fatalerror'));
			}
		} else {
			//loginned forum user has binned baidu,and loginned baiduuser not binned
			showmessage(lang('plugin/acan_open', 'logoutbeforeweixinlogin').'<br />'.lang('plugin/acan_open', 'weixinuser').$info->username);
		}
	}
}
include_once template("acan_open:callback");


?>